import java.util.*;

/**
 * DNA序列
 */
public class DnaSequence {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        loop:while (scanner.hasNext()) {
            String dna = scanner.next();
            int stringLength = Integer.parseInt(scanner.next());
            int max = stringLength/2;
            LinkedHashMap<String, Integer> resultMap = new LinkedHashMap<>();
            for (int i=0; i<dna.length(); i++) {
                String substring = null;
                if (i+stringLength>=dna.length()) {
                    substring = dna.substring(i, dna.length());
                } else {
                    substring = dna.substring(i, i + stringLength);
                }
                String gc = substring.replaceAll("GC", "").replaceAll("CG", "");
                int count = (substring.length()-gc.length())/2;
                if(count == max) {
                    System.out.println(substring);
                    continue loop;
                }
                if (!resultMap.containsKey(substring)) {
                    resultMap.put(substring, count);
                }
            }
            List<Map.Entry<String, Integer>> list = new ArrayList<>(resultMap.entrySet());

            Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() {
                @Override
                public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
                    return o2.getValue().compareTo(o1.getValue());
                }
            });
            Map.Entry<String, Integer> maxEntry = list.stream().findFirst().orElse(null);
            assert maxEntry != null;
            if (maxEntry.getValue() > 0) {
                System.out.println(maxEntry.getKey());
            }
        }
    }
}
